function logBefore(target: any, key: string, descriptor: PropertyDescriptor): PropertyDescriptor {
    const originalMethod = descriptor.value;
  
    descriptor.value = function (...args: any[]): any {
      console.log(`调用函数 ${key}，参数为 ${args}`);
      return originalMethod.apply(this, args);
    };
    return descriptor;
  }
  
class TsAopShopping {
    @logBefore
    addToCart(item: string) {
        // 添加商品到购物车的主要逻辑
        this._doAddToCard(item);
    }

    @logBefore
    checkout() {
        // 结算购物车的主要逻辑
        this._doCheckout();
    }

    private _doAddToCard(item: string) {
        // 添加商品到购物车的主要逻辑
        console.log(`添加商品到购物车：${item}`);
    }

    private _doCheckout() {
        // 结算购物车的主要逻辑
        console.log('结算购物车');
    }
}

const tsShopping = new TsAopShopping();
tsShopping.addToCart("商品A");
tsShopping.addToCart("商品B");
tsShopping.addToCart("商品C");
tsShopping.checkout();
